﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
                xmlns:exslt="http://exslt.org/common"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
    <xsl:output method="xml" indent="yes"/>

  <xsl:include href="helpers.xslt"/>


  <xsl:template name="_sprintItems">
    <xsl:param name="sprintItems"/>
    <xsl:param name="usePreviousPlan"/>
    <xsl:param name="hideDeliveryDate" select="0"/>
    <xsl:param name="endDate"/>    
    <xsl:for-each select="$sprintItems/BacklogItem">
      <xsl:sort select="OccurrenceConstraint" data-type="number"/>
      <xsl:sort select="BusinessPriority" data-type="number"/>
      <xsl:variable name="itemStyle">
        <xsl:choose>
          <xsl:when test="OccurrenceConstraint = 2 and $hideDeliveryDate = 0" >{StaticResource deliveryItemCell}</xsl:when>
          <xsl:otherwise>{StaticResource normalItemCell}</xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <TableRow>
        <TableCell Style="{$itemStyle}" TextAlignment="Right">
          <Paragraph>
            <xsl:value-of select="BacklogItemNumber"/>
          </Paragraph>
        </TableCell>
        <TableCell Style="{$itemStyle}">
          <Paragraph>
            <xsl:value-of select="Name"/>
          </Paragraph>
        </TableCell>
        <TableCell Style="{$itemStyle}" TextAlignment="Right">
          <Paragraph>
            <xsl:variable name="totalHours">
              <xsl:choose>
                <xsl:when test="$usePreviousPlan">
                  <xsl:value-of select="sum(PreviousPlannedHours/PlannedHour/Hours)" />
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="sum(CurrentPlannedHours/PlannedHour/Hours)" />
                </xsl:otherwise>
              </xsl:choose>
            </xsl:variable>
            <xsl:value-of select="$totalHours"/> hrs
          </Paragraph>
        </TableCell>
        <TableCell Style="{$itemStyle}" TextAlignment="Center">
          <Paragraph>
            <xsl:call-template name="itemStatus" />
          </Paragraph>
        </TableCell>
        <xsl:if test="$hideDeliveryDate = 0">
          <TableCell Style="{$itemStyle}" TextAlignment="Right">

            <Paragraph FontWeight="Bold" FontSize="16">
              <xsl:if test="OccurrenceConstraint = 2">
                <xsl:call-template name="formatDate">
                  <xsl:with-param name="dateTime" select="$endDate" />
                </xsl:call-template>
              </xsl:if>
              <xsl:if test="string-length(DeliveryDate) &gt; 0">
                <xsl:call-template name="formatDate">
                  <xsl:with-param name="dateTime" select="DeliveryDate" />
                </xsl:call-template>
              </xsl:if>
            </Paragraph>


          </TableCell>
        </xsl:if>
      </TableRow>
    </xsl:for-each>
  </xsl:template>

  <xsl:template name="sprintDeliveries">    
    <xsl:param name="sprintNumber"/>
    <xsl:param name="usePreviousPlan"/>
    <xsl:param name="hideDeliveryDate" select="0"/>
    <Table>
      <Table.Columns>
        <TableColumn Width="40" />
        <TableColumn />
        <TableColumn Width="60" />
        <TableColumn Width="100" />
        <xsl:if test="$hideDeliveryDate = 0">
          <TableColumn Width="100" />
        </xsl:if>
      </Table.Columns>
      <TableRowGroup>
        
        <xsl:variable name="sprintItems">
          <xsl:choose>
            <xsl:when test="$usePreviousPlan">
              <xsl:copy-of select="/ReportData/ArrayOfBacklogItem/BacklogItem[PreviousPlannedHours/PlannedHour/SprintNumber = $sprintNumber]"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:copy-of select="/ReportData/ArrayOfBacklogItem/BacklogItem[SprintNumber = $sprintNumber]"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>

        <xsl:call-template name="_sprintItems">
          <xsl:with-param name="sprintItems" select="exslt:node-set($sprintItems)"/>
          <xsl:with-param name="usePreviousPlan" select="$usePreviousPlan"/>
          <xsl:with-param name="hideDeliveryDate" select="$hideDeliveryDate"/>
          <xsl:with-param name="endDate" select="/ReportData/Project/Sprints/Sprint[SprintNumber = $sprintNumber]/EndDate"/>          
        </xsl:call-template>
     
      </TableRowGroup>
    </Table>
  </xsl:template>



</xsl:stylesheet>
